<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>RSA</title>
</head>

<body>
    <script src="../libs/jsencrypt.js"></script>
    <script>
    // 待加密数据
    var str = '1234567890';

    // 公钥
    var publicKey = 'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDI3d8LKBsWMacdkN/l0cI3wziS\
VVNGOM3Z1aFyZBxUlj/WP7w03NIWccmEuT8cD/mr85z+2OQCgD0Gj+0xPsgRJ4aa\
fiUcBRfXLqS6yA/RgvJQRnkfnkGQfav5vy6t1AO3cLVUnPAlhXKMsLQwCNNYfUcz\
TAw/H9ka4zsZksDo6wIDAQAB';

    // 私钥
    var privateKey = 'MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBAMjd3wsoGxYxpx2Q\
3+XRwjfDOJJVU0Y4zdnVoXJkHFSWP9Y/vDTc0hZxyYS5PxwP+avznP7Y5AKAPQaP\
7TE+yBEnhpp+JRwFF9cupLrID9GC8lBGeR+eQZB9q/m/Lq3UA7dwtVSc8CWFcoyw\
tDAI01h9RzNMDD8f2RrjOxmSwOjrAgMBAAECgYEAksOybcdvCydacLrjLVu3KeFF\
W35mqx9kIS77mMZXAOMLX7MQBBv4kRew434rA4kUpzQH2RmGd+FVNY9CAsJZkQu6\
XyYK0fSxONlJaMnQJVDdGO5ZQ9hf4I80F1dixWzRQBC2zEHl5euH7AriRIXs2tsX\
llfRXb2HhXW2tz9flIECQQDngeXRhLmwNctRx7SdXabeUe4uo9Y9k40ye07P6gpT\
B8hGYDszxR2pKk6EpA5n8+Dplk6aJqjd3Pt2C9r7frwrAkEA3h4bHscJZq9IJgIG\
OtCfc2x6hGmIuzqUTrA36OvxHbEkcJpTnEw50r7aydN0sLz9siPnDkTeRVXicRoy\
as5mQQJAajM8qhCo3hzPWIS0ZjxAAFy1Vs/xx+2YKEBItzg15ED9rssWXXlfUesG\
efKIaUeHNaCuDikN7jkhYdWubxCEYQJASOiI7mlW5KXUgOVZNiUUscaB0MTzZMGt\
vMaLE6Ge26gx1eRSXZOHx21uU6FdREZE4Bx40243p3qxgX6f3f8yAQJBAOF/00KV\
4PyZgjJXgRUnpWJRkyFrq6GrB/3zYC9cbtI9X5X/8WRvall0o/WpvEUouN/oGwqO\
EnUwHH/WVXtq5so=';


    var encrypt = new JSEncrypt();

    // 公钥加密
    encrypt.setPublicKey(publicKey);
    var ciphertext = encrypt.encrypt(str);

    // 打印密文
    console.log(ciphertext);


    // 私钥解密
    encrypt.setPrivateKey(privateKey);　　
    var translation = encrypt.decrypt(ciphertext);

    // 打印译文
    console.log(translation);
    </script>
</body>

</html>